// const b1 = Buffer.alloc(10);
// const b2 = Buffer.allocUnsafe(10);
// console.log(b1, b2);

/*
  from:
    参数1： 字符串，数组，buffer
    参数2： 字符集
*/
const b3 = Buffer.from("abc");
console.log(b3); // <Buffer 61 62 63>

const b4 = Buffer.from([1, 2, "中"], "utf-8");
console.log(b4); // <Buffer 01 02 00>
const b5 = Buffer.from([0xe4, 0xb8, 0xad], "utf-8");
console.log(b5.toString()); // 中

// from(buffer):只是使用buffer长度创建了一块新的内存空间，和之前的buffer的内存空间并不会联通
const b6 = Buffer.alloc(3);
const b7 = Buffer.from(b6);
console.log(b7); // <Buffer 00 00 00>

b6[0] = 1;
console.log(b6, b7); // <Buffer 01 00 00> <Buffer 00 00 00>
